package com.tanhua.server.controller;

import com.tanhua.commons.vo.HuanXinUser;
import com.tanhua.domain.vo.ContactVo;
import com.tanhua.domain.vo.MessageVo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.interceptor.UserHolder;
import com.tanhua.server.service.IMService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 即时通讯控制层
 */
@RestController
@RequestMapping("/messages")
@Slf4j
public class IMController {

    @Autowired
    private IMService imService;

    /**
     * 添加联系人
     */
    @PostMapping("/contacts")
    public ResponseEntity addContacts(@RequestBody Map<String,Long> paramMap){
        imService.addContacts(paramMap.get("userId"));
        return ResponseEntity.ok(null);
    }

    /**
     * 查询联系人列表
     * (required = false):非必须 可以为空
     */
    @GetMapping("/contacts")
    public ResponseEntity queryContacts(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize,
                                        @RequestParam(required = false) String keyword){
        PageResult<ContactVo> pageResult = imService.queryContacts(page,pagesize,keyword);
        return ResponseEntity.ok(pageResult);
    }


    /**
     * 喜欢列表
     * //评论类型，1-点赞，2-评论，3-喜欢
     */
    @GetMapping("/loves")
    public ResponseEntity loves(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult<MessageVo> pageResult = imService.messageCommentList(page,pagesize,3);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 点赞列表
     * //评论类型，1-点赞，2-评论，3-喜欢
     */
    @GetMapping("/likes")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult<MessageVo> pageResult = imService.messageCommentList(page,pagesize,1);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 评论列表
     * //评论类型，1-点赞，2-评论，3-喜欢
     */
    @GetMapping("/comments")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult<MessageVo> pageResult = imService.messageCommentList(page,pagesize,2);
        return ResponseEntity.ok(pageResult);
    }
}
